
#include "Meshes.h"


abfw::Mesh*  Meshes::PlaneMesh = 0;

//-- A helper file to gain access to meshes created from vertices and indices
void Meshes::InitPlaneMesh(abfw::Platform& platform_)
{
	abfw::Mesh* mesh = platform_.CreateMesh();
	float scale = 0.0195f;

	const abfw::Mesh::Vertex vertices[] =
	{
		{abfw::Vector3(-scale, 0, -scale), abfw::Vector3(0.0f, -1.0f, 0.0f), abfw::Vector2(0.0f, 0.0f)},
		{abfw::Vector3(scale, 0, -scale), abfw::Vector3(0.0f, -1.0f, 0.0f), abfw::Vector2(0.0f, 0.0f)},
		{abfw::Vector3(scale, 0, scale), abfw::Vector3(0.0f, -1.0f, 0.0f), abfw::Vector2(0.0f, 0.0f)},
		{abfw::Vector3(-scale, 0, scale), abfw::Vector3(0.0f, -1.0f, 0.0f), abfw::Vector2(0.0f, 0.0f)}
	};

	mesh->InitVertexBuffer(platform_, static_cast<const void*>(vertices), sizeof(vertices)/sizeof(abfw::Mesh::Vertex), sizeof(abfw::Mesh::Vertex));

	mesh->AllocatePrimitives(1);
	
	abfw::Primitive* primitive = mesh->GetPrimitive(0);

	const UInt32 indices[] = {
    // Back
    0, 1, 2,
    2, 3, 0,
    // Front
    6, 5, 4,
    4, 7, 6,
    // Left
    2, 7, 3,
    2, 6, 7,
    // Right
    0, 4, 1,
	5, 1, 4,
    // Top
    6, 2, 1, 
	5, 6, 1,

	// Bottom
    0, 3, 7,
    0, 7, 4 
	};

	primitive->InitIndexBuffer(platform_, static_cast<const void*>(indices), sizeof(indices)/sizeof(UInt32),sizeof(UInt32));
	primitive->SetType(abfw::TRIANGLE_LIST);
	PlaneMesh = mesh;

}


void Meshes::DestroyAll()
{
	delete PlaneMesh;
}